var app = new Vue({
	el: '#app',
	data: {
		photo: ''
	},
	computed: {
		disabled() {
			if(this.photo){
				return false;
			}
			return true;
		}
	},
	created() {
		const localData = utils.getItem('step3');
		if(localData) {
			for(let [key, value] of Object.entries(localData)) {
				this[key] = value;
			}
		}
	},
	methods: {
		submit: function() {
			if(this.disabled) {
				return;
			}
			utils.setItem('step3', {photo: this.photo});
			utils.jump('password');
		},
		uploadClick: function() {
			this.$refs.photo.click();
		},
		onFileChange: function(event) {
			let file = event.target.files[0];
			if(file.size < Math.pow(1024, 2)) {
				this.successFile(file);
			} else {
				this.zipImg(file);
			}
		},
		zipImg(file) {
			utils.zipImg(file, (base64) => {
				this.photo = base64;
				this.$refs.photo.value = "";
			})
		},
		successFile(file, param) {
			const reader = new FileReader();
			reader.readAsDataURL(file);
			reader.onload = (result) => {
				this.photo = result.target.result;
				this.$refs.photo.value = "";
			};
		},
	}
})